<!--子页面-->
<?php
use yii\helpers\Html;
use yii\helpers\Url;
?>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>系统配置</h5>
                </div>
                <div class="ibox-content">
                    <div class="form-group form-horizontal form-style">
                        <?php
                        $items[] = [
                            'label' => '普通配置',
                            'url'=>Url::current(['class'=>1,'page'=>1]),
                            'active' => $class == 1
                        ];
                        if(Yii::$app->user->id == 1){
                            $items[] = [
                                'label' => '系统配置',
                                'url'=>Url::current(['class'=>0,'page'=>1]),
                            ];
                        }
                        $items[] = [
                            'label' => 'APP版本配置',
                            'url'=>Url::current(['class'=>'app_version','page'=>1]),
                            'active' => $class == 'app_version'
                        ];
                        echo \yii\bootstrap\Tabs::widget(['items'=>$items]); ?>
                    </div>
                    <div class="form-group form-horizontal form-style">
                        <div class="row m-b">
                            <div class="col-sm-2">
                                <?php if($this->context->isAuth('config/edit-ajax-do')){?><button type="button" class="btn btn-primary edit_config">添加配置</button><?php }?>
                            </div>
                        </div>
                    </div>
                    <table class="table table-striped table-bordered table-hover dataTables-example class_table">
                        <thead>
                        <tr class="tb-title">
                            <th class="text-center">ID</th>
                            <th class="text-center">送审版本号</th>
                            <th class="text-center">最新版本</th>
                            <th class="text-center">强更版本</th>
                            <th class="text-center">是否强更</th>
                            <th class="text-center">APK地址</th>
                            <th class="text-center">类别</th>
                            <th class="text-center">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                            <?php if(!empty($list)) foreach($list as $item){ ?>
                            <tr data-id="<?=$item->id?>">
                                <td><?=$item->id?></td>
                                <td ><?=$item->review?></td>
                                <td ><?=$item->latest_version?></td>
                                <td ><?=$item->less_version?></td>
                                <td ><?=$item->latest_force==1?'是':'否'?></td>
                                <td ><?=!empty($item->version_apk)?Yii::$app->params['oss']['host'].'/'.$item->version_apk:'';?></td>
                                <td ><?=$class_arr[$item->class]?></td>
                                <td>
                                    <?php if($this->context->isAuth('config/edit-ajax-do')){ ?>
                                        <a href="javascript:;"
                                           data-id="<?=$item->id?>"
                                           data-review="<?=$item->review?>"
                                           data-latest_version="<?=$item->latest_version?>"
                                           data-latest_version_url="<?=$item->latest_version_url?>"
                                           data-latest_version_note="<?=$item->latest_version_note?>"
                                           data-latest_force="<?=$item->latest_force?>"
                                           data-less_version="<?=$item->less_version?>"
                                           data-comment_url="<?=$item->comment_url?>"
                                           data-apk_size="<?=$item->apk_size?>"
                                           data-is_sale="<?=$item->is_sale?>"
                                           data-version_apk="<?=$item->version_apk?>"
                                           data-class="<?=$item->class?>"
                                           class="btn btn-xs btn-primary edit_config">编辑</a>
                                    <?php }?>
                                </td>
                            </tr>
                            <?php }?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <!--添加编辑课程-->
    <div class="modal inmodal" id="myModal1" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content animated bounceInRight">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                    </button>
                    <h4 class="modal-title">编辑配置</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="ibox float-e-margins">
                                <div class="form-horizontal">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">送审版本号：</label>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control" name="review" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">最新版本：</label>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control" name="latest_version" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">最新版本下载地址：</label>
                                        <div class="col-sm-8">
                                            <input type="text" class="form-control" name="latest_version_url" id="latest_version_url"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">更新日志：</label>
                                        <div class="col-sm-8">
                                            <input type="text" class="form-control" name="latest_version_note" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">是否强制更新(1是,0不是)：</label>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control" name="latest_force" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">最低强制更新版本：</label>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control" name="less_version" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">评论地址：</label>
                                        <div class="col-sm-8">
                                            <input type="text" class="form-control" name="comment_url" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">apk大小：</label>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control" name="apk_size" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">是否匿名购买(1是,0不是)：</label>
                                        <div class="col-sm-3">
                                            <input type="text" class="form-control" name="is_sale" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">类别：</label>
                                        <div class="col-sm-2">
                                            <select name="class" class="form-control">
                                                <?php foreach($class_arr as $key=>$val){ ?>
                                                    <option value="<?=$key?>"><?=$val?></option>
                                                <?php }?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"><span class="text-danger">*</span>APK文件上传：</label>
                                        <div class="col-sm-9">
<!--                                            <div id="upload_image" class="ajaxUpload" style="width: 20px;height: 20px">-->
<!--                                                点击上传apk-->
<!--                                            </div>-->
                                            <button id="upload_image" class="ajaxUpload"> 点击上传apk </button>
                                            <input type="hidden" id="file_edit" name="file_edit">
                                            <input type="text" disabled class="form-control" id="file_edit_view" name="file_edit_view" placeholder="上传成功地址展示">
                                        </div>
                                    </div>
                                    <input type="hidden" name="id" value="0" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary editconfig" data-dismiss="modal">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!--js-->
<script src="/js/plugins/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript" src="/js/plugins/plupload-2.1.2/plupload.full.min.js"></script>
<script type="text/javascript" src="/js/plugins/plupload-2.1.2/oss_uploads.js" ></script>
<script type="text/javascript">

    $(function(){

        $(".edit_config").click(function(){
            var data = $(this).data();
            if(data.id == undefined){
                id=0;
            }else{
                id = data.id;
            }
            $("#myModal1 input[name=id]").val(id);
            $("#myModal1 input[name=review]").val(data.review);
            $("#myModal1 input[name=latest_version]").val(data.latest_version);
            $("#myModal1 input[name=latest_version_url]").val(data.latest_version_url);
            $("#myModal1 input[name=latest_version_note]").val(data.latest_version_note);
            $("#myModal1 input[name=latest_force]").val(data.latest_force);
            $("#myModal1 input[name=less_version").val(data.less_version);
            $("#myModal1 input[name=comment_url]").val(data.comment_url);
            $("#myModal1 input[name=apk_size]").val(data.apk_size);
            $("#myModal1 input[name=is_sale]").val(data.is_sale);
            $("#myModal1 select[name=class] option[value="+data.class+"]").prop('selected',true);
            $('#myModal1').modal('show').find('.modal-title').text((id?'编辑':'添加')+'配置');
        });

        $(".editconfig").click(function(){
            var data={};
            data.id= $("#myModal1 input[name=id]").val();
            data.review= $("#myModal1 input[name=review]").val();
            data.latest_version= $("#myModal1 input[name=latest_version]").val();
            data.latest_version_url= $("#myModal1 input[name=latest_version_url]").val();
            data.latest_version_note= $("#myModal1 input[name=latest_version_note]").val();
            data.latest_force= $("#myModal1 input[name=latest_force]").val();
            data.less_version= $("#myModal1 input[name=less_version]").val();
            data.comment_url= $("#myModal1 input[name=comment_url]").val();
            data.apk_size= $("#myModal1 input[name=apk_size]").val();
            data.is_sale= $("#myModal1 input[name=is_sale]").val();
            data.class= $("#myModal1 select[name=class]").val();
            if((data.class ==1 ||data.class ==3) && $("#myModal1 input[name=file_edit]").val().length>0){
                data.version_apk= $("#myModal1 input[name=file_edit]").val();
            }
            data.type = 'app_version';
            $.ajax({
                type: "post",
                url: "edit-ajax-do",
                data: data,
                dataType: "json",
                success: function(param){
                    if(param.code == '20000'){
                        alert(param.message);
                        location.reload();
                    }else{
                        alert(param.message);
                    }
                }
            });
        });

    })
    var type = $("#myModal1 select[name=class]").val();
    if(type ==1 || type ==3) {
        //apk文件上传
        var ossUpload = <?=$ossUpload?>;
        upload_apk({
            'browse_button': 'upload_image',
        }, function (up, file, info) {
            var api = "<?php echo Yii::$app->params['oss']['host']?>";
            $('#file_edit_view').val(api+g_object_name);
            $('#file_edit').val(g_object_name);
            $('#latest_version_url').val(api+g_object_name);
        });
    }
</script>
<!--js-->
<!--/子页面-->


